import { createApp } from "vue";

import {
  renderWithQiankun,
  qiankunWindow,
} from "vite-plugin-qiankun/dist/helper";

import App from "./App.vue";

let app: any = null;
const render = (props: any = {}) => {
  const { container } = props;
  app = createApp(App);
  app.mount(container ? container.querySelector("#app") : "#app");
};

renderWithQiankun({
  mount(props) {
    const state = props.actions.getGlobalState();
    console.log(state);
    render(props);
  },
  bootstrap() {},
  unmount() {
    app.unmount();
    app = null;
  },
  update() {},
});

if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  render({});
}
